home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / std / c / 4 < prev    next >
Encoding:
Internet Message Format  |  1996-08-06  |  2.2 KB

  1. Path: monkeys.com!not-for-mail
  2. From: rfg@monkeys.com (Ronald F. Guilmette)
  3. Newsgroups: comp.std.c
  4. Subject: Circular buffering for FILEs?  Why not?
  5. Date: 1 Jan 1996 13:03:01 -0800
  6. Organization: Infinite Monkeys & Co.
  7. Message-ID: <4c9i65$3b6@segfault.monkeys.com>
  8. NNTP-Posting-Host: segfault.monkeys.com
  9.  
  10. I have a question about the traditional implementation of buffered FILEs.
  11.  
  12. (My apologies to readers of comp.std.c.  I know this isn't a question
  13. which relates directly to the text of the C standard, but I do need to
  14. put the question to people who are well versed in the details of C imple-
  15. mentations, and comp.std.c is one likely place to find such people.)
  16.  
  17. Traditional implementations of getc and putc look pretty much as follows:
  18.  
  19. ----------------------------------------------------------------------------
  20. #define getc(p)         (--(p)->_cnt < 0 ? __filbuf(p) : (int)*(p)->_ptr++)
  21. #define putc(x, p)      (--(p)->_cnt < 0 ? __flsbuf((unsigned char) (x), (p)) \
  22.                                 : (int)(*(p)->_ptr++ = (x)))
  23. ----------------------------------------------------------------------------
  24.  
  25. The important point to note here is each of these macros causes the
  26. ``file pointer'' (_ptr) to be incremented... in a very simple-minded
  27. fashion... whenever a character is taken from, or added to the FILE's
  28. buffer (respectively).
  29.  
  30. From this fact I deduce that traditional implementations of the entire
  31. stdio set of functions _do not_ treat FILE buffers as so-called ``circular
  32. buffers'' but rather treat them a mere linear buffers.
  33.  
  34. My question is just this... Why?
  35.  
  36. Given that traditional implementations of the FILE structure include a
  37. ``_cnt'' field, it seems to me that it would have been possible... albeit
  38. at a slight cost... to treat FILE buffers as circular buffers, wraping
  39. the value of _ptr back to the physical beginning of the buffer each time
  40. it was seen to have passed the physical end of the buffer.  But it seems
  41. that nobody does this.  Why not?
  42. -- 
  43.  
  44. -- Ron Guilmette, Roseville, CA -------- Infinite Monkeys & Co. ------------
  45. ---- E-mail: rfg@monkeys.com ----------- Purveyors of Compiler Test Suites -
  46. ------ Copyright (c) 1995 by Ronald F. Guilmette; All rights reserved. -----
  47.